import moment from 'moment'
import { BEAM_TYPE } from '@/enum'

/**
 * 波束类型
 * @author Farley
 * @date 2021-12-02
 * @param {any} state
 * @returns {any}
 */
export function beamTypeFilter(state) {
  return BEAM_TYPE[state]
}

/**
 * 时间格式化输出北京时间
 * @author Farley
 * @date 2021-12-02
 * @param {any} time
 * @returns {any}
 */
export function timeFormatFilter(time) {
  let t = moment(time)
  let ymd = t.format('YYYY-MM-DD')
  let hms = t.format('HH:mm:ss')
  return { full: `${ymd} ${hms}`, ymd, hms }
}

export function utcToBeijing(time) {
  if (time) {
    let t = moment(time).utcOffset(8).format('YYYY-MM-DDTHH:mm:ss') + 'Z'
    return t
  } else {
    return undefined
  }
}

export function beijingToUtc(time) {
  if (time) {
    let t = moment(time).utcOffset(-8).format('YYYY-MM-DDTHH:mm:ss') + 'Z'
    return t
  } else {
    return undefined
  }
}

export function timeToUtc(time) {
  if (time) {
    let t = moment(time).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
    return t
  } else {
    return undefined
  }
}